<%--
  Created by IntelliJ IDEA.
  User: LT
  Date: 2018-10-25
  Time: 15:46
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>Title</title>
    <link href="${pageContext.request.contextPath}/static/hplus/css/bootstrap.min.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/hplus/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <script src="${pageContext.request.contextPath}/static/hplus/js/jquery.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/hplus/js/bootstrap.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/hplus/js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/hplus/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>

    <link href="${pageContext.request.contextPath}/static/hplus/css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">

    <link href="${pageContext.request.contextPath}/static/hplus/css/animate.min.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/hplus/css/style.min862f.css?v=4.1.0" rel="stylesheet">

    <script>
        //得到查询的参数
        function queryParams (params) {


        };

        $(function () {

            $("#usertb").bootstrapTable({

                url:'${pageContext.request.contextPath}/jinhuols/query',
                //启用分页，但是默认情况下，是客户端分页的
                pagination:true,
                //启用服务器端分页
                sidePagination:'server',
                //设置每页多少条数据
                pageSize:15,
                pageList:[2,4,8,16],
                height:450,
                clickToSelect:true,
                singleSelect:true,
                pageNumber:1,
                //请求服务器数据时，你可以通过重写参数的方式添加一些额外的参数，例如 toolbar 中的参数 如果 queryParamsType = 'limit' ,返回参数必须包含
                //limit, offset, search, sort, order 否则, 需要包含:
                //pageSize, pageNumber, searchText, sortName, sortOrder.
                // 返回false将会终止请求。
                queryParams:function(params){
                    var temp = {  //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                        limit: params.limit,  //页面大小
                        offset: params.offset, //页码
                        huoname:$("#huoname").val()
                    };
                    return temp;
                },
                columns:[
                    {
                        checkbox:true,
                    },
                    {
                        field:'huoid',
                        title:'编号',
                    },
                    {
                        field:'huoname',
                        title:'名称'
                    },

                    {
                        field:'huolei',
                        title:'类别',
                        formatter (value, row, index, field){
                            if (row.huolei == 1) {
                                return "水果";
                            }else if(row.huolei == 2){
                                return "海鲜";
                            }else if(row.huolei == 3){
                                return "肉类";
                            }else if(row.huolei == 4){
                                return "饼干";
                            }else if(row.huolei == 5){
                                return "牛奶";
                            }else if(row.huolei == 6){
                                return "薯片";
                            }else if(row.huolei == 7){
                                return "洗发水";
                            }else if(row.huolei == 8){
                                return "沐浴露";
                            }else if(row.huolei == 9){
                                return "洗面奶";
                            }else if(row.huolei == 10){
                                return "大米";
                            }else if(row.huolei == 11){
                                return "调料";
                            }else if(row.huolei == 12){
                                return "油";
                            }else if(row.huolei == 13){
                                return "洗衣液";
                            }else if(row.huolei == 14){
                                return "洗衣灵";
                            }else if(row.huolei == 15){
                                return "纸";
                            }
                        }

                    },

                    {
                        field:'huodan',
                        title:'规格',
                        formatter (value, row, index, field){
                            if (row.huodan == 1) {
                                return "斤";
                            }else if(row.huodan == 2){
                                return "个";
                            }else if(row.huodan == 3){
                                return "盒";
                            }else if(row.huodan == 4){
                                return "桶";
                            }else if(row.huodan == 5){
                                return "箱";
                            }else if(row.huodan == 6){
                                return "袋";
                            }else if(row.huodan == 7){
                                return "瓶";
                            }
                        }
                    },
                    {
                        field:'huoshu',
                        title:'数量'
                    },
                    {
                        field:'huodanjia',
                        title:'成本'
                    },
                    {
                        field:'huozongjia',
                        title:'总价'
                    },



                ]
            }) ;
        }) ;



        function searcha() {
            var opts = $("#usertb").bootstrapTable("getOptions") ;
            var limit = opts.pageSize ;
            var offset = (opts.pageNumber-1) * limit;
            var username = $("#username").val() ;
            $.post("${pageContext.request.contextPath}/jinhuols/query",{'huoname':username,'limit':limit,'offset':offset},function (data) {
                // var mydata = eval("("+data+")") ;
                //重新绑定表格数据
                $("#usertb").bootstrapTable('load',data) ;
            })
        }



        function GetRandomNum(Min,Max)
        {
            var Range = Max - Min;
            var Rand = Math.random();
            return(Min + Math.round(Rand * Range));
        }
        var num = GetRandomNum(10000,99999);



        function doadd(){
            var riqi=$("#div1 [name=shijian]").val();
            var gonghuo=$("#div1 [name=account]").val();
            var yingfu=$("#div1 [name=scount]").val();
            var shifu=$("#div1 [name=chengben]").val();
            var jingban=$("#div1 [name=jingban]").val();


            $.post('${pageContext.request.contextPath}/jinhuo/addhuo',{"danhao":num,"riqi":riqi,'gonghuo':gonghuo,'yingfu':yingfu,'shifu':shifu,'jingban':jingban},function(data){
                if(data>0){
                    // var mydata = eval("("+data+")") ;
                    //重新绑定表格数据
                    searcha();
                    $("#hytb").bootstrapTable("load",data);
                    $("#div1").modal('hide');
                }
            });
            bac();
        }

        /*        function newNnb() {
                    var num = $("#juesebody3 input[name=dwid]").val();
                    var tos = $("#juesebody4 input[name=danjia]").val();
                    $("#juesebody5 input[name=danjia]").val(parseInt(num) * parseInt(tos));
                }*/


        function getNowFormatDate() {
            var date = new Date();
            var seperator1 = "-";
            var year = date.getFullYear();
            var month = date.getMonth() + 1;
            var strDate = date.getDate();
            if (month >= 1 && month <= 9) {
                month = "0" + month;
            }
            if (strDate >= 0 && strDate <= 9) {
                strDate = "0" + strDate;
            }
            var currentdate = year + seperator1 + month + seperator1 + strDate;
            $("#shijian").val(currentdate);

        }

        function fukuan() {
            $("#div1").modal("show") ;
            getNowFormatDate();
            abc();

        }
        var a ="";
        function bac() {
            var opts = $("#usertb").bootstrapTable("getData");
            var countNum = 0;
            for (var i=0 ; i < opts.length ; i++) {
                $.post('${pageContext.request.contextPath}/jinhuo/updata',{"sid":opts[i].huoid,'scount':opts[i].huoshu},function(data){

                    if(data>0){
                        searcha();
                        $("#hytb").bootstrapTable('load',data) ;
                        $("#Div2").modal('hide');

                    };
                });
                $.post('${pageContext.request.contextPath}/jinhuoxx/addxx',{"dh":num,'spid':opts[i].huoid,'spname':opts[i].huoname,'splei':opts[i].huolei,'spdan':opts[i].huodan,'spshu':opts[i].huoshu,'spjia':opts[i].huodanjia,'spzong':opts[i].huozongjia},function(data){
                    if(data>0){

                    }
                });
            }

            del();

        }


        function abc() {
            var opts = $("#usertb").bootstrapTable("getData");
            var countNum = 0;
            for (var i=0 ; i < opts.length ; i++) {
                countNum += opts[i].huozongjia;
            }

            $("#yingfu").val((countNum).toFixed(1));
            $("#shifu").val((countNum).toFixed(1));
        }



        $(function () {
            $.post("${pageContext.request.contextPath}/jinhuols/query1",function (data) {
                var _this = $("#div1 select[name=account]");
                $(_this).empty();
                for (var i=0 ;i < data.length;i++) {
                    $(_this).append("<option>"+data[i].ghuo+"</option>");
                }
            });
        });


        function del() {

            $.post('${pageContext.request.contextPath}/jinhuo/del',function(data){
                location.reload();
            });

        }



    </script>

    <script>
        $(function () {
            $.post("${pageContext.request.contextPath}/jinhuols/all",{'limit':15,'offset':0},function (data) {
                if (data) {
                    $("#fukuan").attr('disabled',true);
                } else {
                    $("#fukuan").attr('disabled',false);
                }
            });
        });
    </script>



</head>



<body class="gray-bg">
<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-sm-4" >
        <h2>采购进货</h2>
        <ol class="breadcrumb">

        </ol>
    </div>

</div>



<%--商品付款--%>

<div class="modal fade" id="div1" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">货物付款</h4>
            </div>
            <div class="modal-body">

                <div class="row">
                    <label class="col-sm-3 control-label" style="color: #010101 ;width: 110px"><h2>供货商:</h2></label>
                    <div class="col-md-4" id="juesebody3" style="margin-top: 15px">
                        <select class="form-control m-b" name="account" style="width: 250px">

                            <option> </option>

                        </select>
                </div>

                </div>
                <div class="row">
                    <label class="col-sm-3 control-label" style="color: #010101;width: 110px"><h2>应付$:</h2></label>
                    <div class="col-md-4" id="juesebody1" style="margin-top: 15px;width: 110px">
                        <input style="color: #010101 ;width: 100px"name="scount" id="yingfu" readOnly="true" type="text"class="form-control">
                    </div>
                    <label class="col-sm-3 control-label" style="color: #010101;width: 110px;margin-left: 30px"><h2>实付$:</h2></label>
                    <div class="col-md-4" id="juesebody2" style="margin-top: 15px">
                        <input style="color: #010101 ;width: 100px"name="chengben" id="shifu" type="text" class="form-control">
                    </div>

                </div>
                <div class="row">
                    <label class="col-sm-3 control-label" style="color: #010101;width: 110px"><h2 style="width: 160px">经办人:</h2></label>
                    <div class="col-md-4" id="juesebody4" style="margin-top: 15px;width: 110px">
                        <input style="color: #010101 ;width: 100px"name="jingban" value="${user.username}"  readOnly="true" id="ren" type="text" class="form-control">
                    </div>
                    <label class="col-sm-3 control-label" style="color: #010101;width: 110px;margin-left: 30px"><h2>时间:</h2></label>
                    <div class="col-md-4" id="juesebody5" style="margin-top: 15px">
                        <input style="color: #010101 ;width: 100px"name="shijian" id="shijian"readOnly="true" type="text" class="form-control">
                    </div>

                </div>


            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" onclick="doadd()"class="btn btn-primary">结账</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->



<div class="wrapper wrapper-content" style="background: #EDF2F8">
    <div class="row">
<%--
          <div class="col-md-1" style="width:200px ;margin-left:300px;height:50px" >
              <span class="input-group-addon" id="basic-addon3">供货商</span>
              <input type="text" style="height:35px" class="form-control" id="basic-url" aria-describedby="basic-addon3">
          </div>
--%>






<%--

        <div class="col-md-1"style="margin-left:90px; margin-top: -15px">
            <div class="title-action">
                <a href="" onclick="del1()" class="btn btn-primary">删除货物</a>
            </div>
        </div>
--%>

    <div class="col-md-1"style="margin-left:1500px; margin-top: -15px">
        <div class="title-action">
            <button id="fukuan" onclick='fukuan()'class="btn btn-w-m btn-warning">货物付款</button>
        </div>
    </div>



    </div>
</div>


<div class="panel panel-default">

    <div class="panel-body" <%--style="width:850px;height:850px"--%>>

        <table id="usertb"></table>

    </div>
</div>









</body>

</html>

